import time

from selenium.webdriver import ActionChains


async def testAuditFlow(browser):
    try:
        browser.find_element_by_tag_name('aside')
        browser.find_element_by_tag_name('aside').find_elements_by_xpath("//span[contains(text(),'审核流程')]")[1].click()  # 点击导航
        # browser.find_element_by_class_name('el-aside').find_element_by_xpath("//span[contains(text(),'审核流程')]").click()
        time.sleep(0.5)
        menus = browser.find_elements_by_class_name('popover-menu')  # 所有菜单
        nowMenus = menus[len(menus) - 1]  # 获取最后一个菜单，点开的都回默认为最后一个
        # 点击第一排第一个
        nowMenus.find_elements_by_class_name('menu-prop__item')[0].find_elements_by_tag_name('a')[0].click()
        # browser.find_elements_by_xpath("//span[contains(text(),'单据表')]")[0].click()  # 点击菜单
        time.sleep(2)
        queryButton = \
            browser.find_elements_by_class_name('el-form-item__content')[3].find_elements_by_tag_name('button')[
                0]  # 查询按钮
        queryButton.click()

        td = browser.find_element_by_class_name('el-table__body-wrapper').find_element_by_tag_name(
            'tr').find_elements_by_tag_name('td')[5]
        # 双击打开预审
        ActionDoubleClick = ActionChains(browser).double_click(td)
        ActionDoubleClick.perform()
        time.sleep(1)
        browser.find_element_by_xpath("//label[contains(text(),'生产车间:')]/following-sibling::div/div/div").click()
        time.sleep(0.1)
        selectsMenu = browser.find_element_by_class_name('vue-treeselect__menu')
        selectsMenu.click();
        print(selectsMenu)
        print(selectsMenu.text)
        time.sleep(0.5)
        browser.find_element_by_xpath("//label[contains(text(),'备注:')]/following-sibling::div/div/textarea").send_keys(
            "这是一条自动化测试数据！")  # 填写备注
        time.sleep(0.2)
        browser.find_element_by_tag_name('footer').find_elements_by_tag_name('button')[0].click()  # 保存
        time.sleep(1)
        # 双击打开钱审
        td = browser.find_element_by_class_name('el-table__body-wrapper').find_element_by_tag_name(
            'tr').find_elements_by_tag_name('td')[5]
        ActionDoubleClick = ActionChains(browser).double_click(td)
        ActionDoubleClick.perform()
        time.sleep(1)
        browser.find_element_by_tag_name('footer').find_elements_by_tag_name('button')[0].click()  # 保存
        time.sleep(1)
        # 双击打开财审
        td = browser.find_element_by_class_name('el-table__body-wrapper').find_element_by_tag_name(
            'tr').find_elements_by_tag_name('td')[5]
        ActionDoubleClick = ActionChains(browser).double_click(td)
        ActionDoubleClick.perform()
        time.sleep(1)
        browser.find_element_by_tag_name('footer').find_elements_by_tag_name('button')[0].click()  # 保存
        time.sleep(1)
        # 双击打开产审
        td = browser.find_element_by_class_name('el-table__body-wrapper').find_element_by_tag_name(
            'tr').find_elements_by_tag_name('td')[5]
        ActionDoubleClick = ActionChains(browser).double_click(td)
        ActionDoubleClick.perform()
        time.sleep(1)
        browser.find_element_by_tag_name('footer').find_elements_by_tag_name('button')[0].click()  # 保存
        time.sleep(2)
    finally:
        print(browser.current_url, '完成')
        # browser.close()
